package com.example.repeatsubmit.policy;

import com.alibaba.fastjson2.JSON;
import com.example.repeatsubmit.exception.RepeatSubmitException;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

/**
 * @author caoqianhuan
 * @date 2022/8/19
 * @Description:
 */

public abstract class RepeatPolicy {
    protected Long interval;
    protected final String REPEAT_SUBMIT_FLAG = "1";

    public abstract boolean isRepeatSubmit(HttpServletRequest servletRequest) throws RepeatSubmitException;

    public Long getInterval() {
        return interval;
    }

    public void setInterval(Long interval) {
        this.interval = interval;
    }

    public String getLastRequest(HttpServletRequest servletRequest) {
        String url = servletRequest.getRequestURI();
        String sessionId = servletRequest.getRequestedSessionId();
        String params = JSON.toJSONString(servletRequest.getParameterMap());
        return url + sessionId + params;
    }
}
